#!/usr/bin/python

import os
import os.path

printTreeCommand = "../pyprinttree"
temporaryFile = "testout.txt"

errorCount = 0
totalCount = 0

for filename in os.listdir('.'):
	if filename.endswith( '.py' ) and '-' in filename:
		values = filename[:-3].split('-', 1)
		number, name = values[0], values[1]
		
		totalCount += 1
		
		if not os.path.exists( '%s.txt' % ( filename[:-3] ) ):
			print "%s %s: ERROR: No expected output" % ( number, name )
			errorCount += 1
			continue
		
		print "%s %s: " % (number, name),
		
		os.system( "%s %s > %s" % ( printTreeCommand, filename, temporaryFile ) )
		
		f = file( '%s.txt' % ( filename[:-3] ) )
		expected = f.read()
		f.close()
		
		f = file( temporaryFile )
		output = f.read()
		f.close()
		
		if expected == output:
			print "SUCCESS"
		else:
			errorCount += 1
			print "ERROR"
		
		os.unlink( temporaryFile )

print
print "%d/%d tests passed (%.2f%%)" % ( totalCount - errorCount, totalCount, float(totalCount - errorCount) / totalCount * 100 )
